#!D:\Python27\python.exe
# -*- coding: utf-8 -*-
'''
    CGI Controller

    :copyright: (c) 2014 by Duxin.
'''
import traceback

from exception import ParameterError

class App(object):
    '''
        Caller for Command object. This class catches exceptions raised by Command objects
        and takes elegant way to solve it or report it
    '''
    
    @staticmethod
    def start(cgi):
        try:
            cgi.is_param_right()
        except ParameterError, e:
            cgi.write(e)
            return
        
        try:
            return_string = cgi.execute()
            
            if return_string == 'error':
                cgi.write('error_程序执行错误')
            else:
                cgi.write(return_string)
        except Exception, e:
            cgi.write(e)
            print traceback.format_exc()


